<template>
	<view class="main-box ">

		<u-popup v-model="shows" mode="center" v-if="flag==2">
			<view class="" style="width: 100%;text-align: center;">
				<!-- 	<image class="" mode="widthFix" src="/static/success.png" v-if="flag==1" class="img"></image> -->
				<image mode="widthFix" src="/static/err1.png" @click="errs" class="img"></image>
				<image src="../../static/queren.png" mode="widthFix" class="img" style="margin-top: 20rpx;"
					@click="errs"></image>
			</view>
		</u-popup>
		<view class="" style="background-color: #347af0;height: 100vh;" v-if="flag==1">
			<image src="../../static/sucesss.png" mode="widthFix" style="width: 100%;"></image>
		</view>
		<view class="" style="background-color: #e1f3ff;height: 100vh;" v-if="flag==3">
			<image src="https://web.78keji.cn/images/yundian/背景@3x.png" mode="widthFix" style="width: 100%;"></image>
			<view class="" style="padding: 24rpx;">
				<view class="bns">
					<image src="https://web.78keji.cn/images/yundian/biaoti1.png" mode="widthFix" style="width: 100%;">
					</image>
					<image src="https://web.78keji.cn/images/yundian/1.gif" mode="widthFix"
						style="width: 100%;margin-top: 20rpx;"></image>
					<image src="https://web.78keji.cn/images/yundian/btn2@3x.png" mode="widthFix"
						style="width: 100%;margin-top:30rpx;" @click="kabao"></image>

				</view>
				<view class="bns" style="margin-top: 40rpx;">
					<image src="https://web.78keji.cn/images/yundian/biaoti2.png" mode="widthFix" style="width: 100%;">
					</image>
					<image src="https://web.78keji.cn/images/yundian/2.gif" mode="widthFix"
						style="width: 100%;margin-top: 20rpx;"></image>
					<image src="https://web.78keji.cn/images/yundian/btn.png" mode="widthFix"
						style="width: 100%;margin-top:30rpx;" @click="chongzhi"></image>

				</view>
				<view class="" style="height: 100rpx;">

				</view>
			</view>
		</view>

		<view class="" v-if="type==1">
			<ad></ad>
		</view>
		<!-- style="position: fixed;bottom: 0;height: 500rpx;overflow-y: auto;" -->
		<view class="" v-if="type==2" >
			<ads onSuccess="onSuccess" onClose="onClose" ></ads>
		</view>

	</view>
</template>
<script>
	import {
		getdata,
		addLog,
		getUrl,
		addNum,
		statusx,
		getcode,
		logs
	} from '../../api/index.js'
	export default {
		data() {
			return {
				interstitialAd: null,
				flag: 0,
				shows: true,
				a: "",
				times: '0',
				type: "",
				spaceCode: ""
			}
		},
		components: {

		},

		methods: {
			// #ifdef MP-ALIPAY
			onSuccess() {
				console.log('成功88888888')
				logs({
					a: my.getStorageSync({
						key: 'a'
					}).data,
					eventType: 3,
					xcx: 3,
					deviceid: my.getStorageSync({
						key:'deviceid'
					}).data,
					spaceCode: this.spaceCode
				}).then((res) => {
					console.log(res)
				})

			},
			onClose() {
				// this.flagg=true
				// this.onInsuranceStatus()
				console.log("广告关闭")
				my.exitMiniProgram();
			},
			chongzhi() {
				let link = "https://render.alipay.com/p/s/i/?scheme=" + encodeURIComponent(
					"alipayqr://platformapi/startapp?saId=10000003")

				my.ap.navigateToAlipayPage({
					path: link
				})
			},
			kabao() {
				let link = "https://render.alipay.com/p/s/i/?scheme=" + encodeURIComponent(
					"alipayqr://platformapi/startapp?saId=88888888")

				my.ap.navigateToAlipayPage({
					path: link
				})


			},
			errs() {
				if (my.getStorageSync({
						key: 'a'
					}).data == undefined) {
					my.setStorageSync({
						key: 'a',
						data: 666666
					})
				}

				let url = encodeURIComponent(my.getStorageSync({
					key: 'url'
				}).data)

				if (url != '') {
					let link = "https://render.alipay.com/p/s/i/?scheme=" + encodeURIComponent(
							"alipays://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode=") +
						encodeURIComponent(url)
					my.ap.navigateToAlipayPage({
						path: link
					})
				} else {
					my.showToast({
						type: 'fail',
						content: '抱歉，当前暂无可领取福利',
						duration: 3000,
						success: () => {

						},
					});
				}

			}
			// #endif
		},
		onLoad(option) {
			this.$scope.onSuccess = this.onSuccess.bind(this)
			this.$scope.onClose = this.onClose.bind(this)
			let link = "https://render.alipay.com/p/s/i/?scheme=" + encodeURIComponent(
				"alipayqr://platformapi/startapp?saId=88888888")
			console.log(link)
			//其他小程序调过来
			uni.setStorageSync('times', 0)
			// #ifdef MP-ALIPAY

			if (option.mobile) {
				my.setStorageSync({
					key: 'phone',
					data: option.mobile
				})

			}
			if (option.a) {
				my.setStorageSync({
					key: 'a',
					data: option.a
				})

			}

			if (option.param) {
				my.setStorageSync({
					key: 'param',
					data: option.param
				})

			}

			getUrl({
				a: my.getStorageSync({
					key: 'a'
				}).data,
				param: my.getStorageSync({
					key: 'param'
				}).data,
				mobile: my.getStorageSync({
					key: 'phone'
				}).data,
			}).then((result) => {
				if (result.code == 1 && result.data.ad_h5_to_url != '') {

					my.setStorageSync({
						key: 'url',
						data: result.data.ad_h5_to_url
					})

				} else {
					my.setStorageSync({
						key: 'url',
						data: ''
					})
				}
			})


			// #endif

		},

		onUnload() {

		},

		onShow() {
			// #ifdef MP-ALIPAY

			// uni.setStorageSync('a', option.a)
			getcode({
				a: my.getStorageSync({
					key: 'a'
				}).data,
				xcx: 3
			}).then((res) => {
				this.spaceCode = res.data.spaceCode
				this.type = res.data.type
				logs({
					a: my.getStorageSync({
						key: 'a'
					}).data,
					eventType: 4,
					xcx: 3,
					spaceCode: this.spaceCode,
					pages: "pages/unit/unit",
					orderNo: my.getStorageSync({
						key: 'orderNo'
					}).data,
					deviceid: my.getStorageSync({
						key:'deviceid'
					}).data
				}).then((res) => {
					console.log(res)
				})
				console.log(res, '1111111111')
				if (this.type == 1) {

					if (uni.getStorageSync('times') == 0) {

						uni.setStorageSync('times', 1)
					} else {
						const oders = my.getStorageSync({
							key: 'orderNo'
						}).data
						console.log(oders)
						if (oders) {
							getdata({
								orderNo: oders
							}).then((resx) => {
								console.log(resx, 99999999999)
								statusx({
									a: my.getStorageSync({
										key: 'a'
									}).data
								}).then((res) => {
									console.log(res)
									if (res.data.coe == 99) {
										if (res.data.pzb_ljj == 0) {
											this.flag = 1
											//成功不发放
										} else if (res.data.pzb_ljj == 1) {
											this.flag = 3
											//成功发放
										} else if (res.data.pzb_ljj == 3) {
											if (res.data.pzb_ljj_3_url != '') {
												let link =
													"https://render.alipay.com/p/s/i/?scheme=" +
													encodeURIComponent(
														"alipays://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode="
													) +
													encodeURIComponent(encodeURIComponent(res.data
														.pzb_ljj_3_url))
												my.ap.navigateToAlipayPage({
													path: link
												})
											}

										}
									} else {
										this.flag = 0
										let url = encodeURIComponent(my.getStorageSync({
											key: 'url'
										}).data)
										if (url != '') {
											let link = "https://render.alipay.com/p/s/i/?scheme=" +
												encodeURIComponent(
													"alipays://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode="
												) +
												encodeURIComponent(url)
											my.ap.navigateToAlipayPage({
												path: link
											})
										}


									}

								})

							}).catch((err) => {
								console.log(err, '59526565')
								this.flag = 2
							})
						}


					}
				}
			})




			// #endif

		},


		watch: {


		},
		computed: {

		}
	}
</script>

<style lang='scss'>
	.main-box {
		min-height: 100%;
		position: relative;
		/* 	background-color: red; */



	}

	.img {
		height: 80%;
		width: 80%;
	}

	.box {
		height: 100%;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.bns {
		width: 100%;
		background: #FFFFFF;
		box-shadow: 0rpx 2rpx 5rpx 0rpx rgba(16, 104, 195, 0.3);
		border-radius: 25rpx;
		padding: 50rpx 50rpx 0 50rpx;
	}
</style>